package com.haier.npt.sso.api;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.haier.npt.common.JsonResult;
import com.haier.npt.exception.BizBaseException;
import com.haier.npt.exception.ExceptionCode;
import com.haier.npt.security.domain.SysApp;
import com.haier.npt.sso.authentication.cache.TokenCacheService;
import com.haier.npt.sso.i18n.SSOExceptionCode;
import com.haier.npt.sso.resources.SysAppCacheResource;



@RestController
public class SysAppCacheController implements SysAppCacheResource {
	
	@Autowired
	private TokenCacheService tokenCacheService ; 

	/**
	 * 根据token获取对应的app
	 * @param token
	 * @return
	 */
	@Override
	@RequestMapping(value="/internal/sysapps/getByToken",method= RequestMethod.GET)
	public  JsonResult<List<SysApp>> findAppByToken(@RequestParam(value="token" ,required=true)String token){
		List<SysApp> sysApps = tokenCacheService.getAppFromCache(token);
		if(sysApps==null){
			return JsonResult.error(ExceptionCode.TOKEN_INVALID);
		}
		return JsonResult.success(sysApps) ; 
	}
}
